#!/bin/bash

# BSC API 测试脚本
# 使用方法: ./test-bsc-api.sh

BASE_URL="http://localhost:7172/api/bsc"

echo "🚀 BSC LaunchPad API 测试开始..."

echo "📊 1. 获取平台统计"
curl -s -X GET "$BASE_URL/stats" | jq '.'

echo -e "\n📋 2. 获取代币列表"
curl -s -X GET "$BASE_URL/tokens?page=1&limit=10" | jq '.'

echo -e "\n🎯 3. 创建代币发射 (模拟)"
curl -s -X POST "$BASE_URL/tokens" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "TestToken",
    "symbol": "TEST",
    "description": "A test token for BSC LaunchPad",
    "website": "https://testtoken.com",
    "telegram": "https://t.me/testtoken",
    "twitter": "https://twitter.com/testtoken",
    "targetAmount": 10,
    "creatorPrivateKey": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
  }' | jq '.'

# 等待一秒让数据库操作完成
sleep 1

echo -e "\n🔍 4. 获取特定代币信息"
curl -s -X GET "$BASE_URL/tokens/1" | jq '.'

echo -e "\n💰 5. 购买代币预览"
curl -s -X POST "$BASE_URL/tokens/preview" \
  -H "Content-Type: application/json" \
  -d '{
    "launchId": 1,
    "bnbAmount": 1.0
  }' | jq '.'

echo -e "\n🛒 6. 购买代币 (模拟)"
curl -s -X POST "$BASE_URL/tokens/buy" \
  -H "Content-Type: application/json" \
  -d '{
    "launchId": 1,
    "bnbAmount": 1.0,
    "buyerAddress": "0x742dB4C8A7b1234567890abcdef1234567890abc",
    "buyerPrivateKey": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
  }' | jq '.'

echo -e "\n💸 7. 出售代币预览"
curl -s -X POST "$BASE_URL/tokens/preview" \
  -H "Content-Type: application/json" \
  -d '{
    "launchId": 1,
    "tokenAmount": 500
  }' | jq '.'

echo -e "\n🎯 8. 获取用户贡献"
curl -s -X GET "$BASE_URL/tokens/1/contributions/0x742dB4C8A7b1234567890abcdef1234567890abc" | jq '.'

echo -e "\n📈 9. 获取联合曲线信息"
curl -s -X GET "$BASE_URL/tokens/1/bonding-curve" | jq '.'

echo -e "\n📱 10. 获取社交媒体信息"
curl -s -X GET "$BASE_URL/tokens/1/social" | jq '.'

echo -e "\n📊 11. 获取价格历史"
curl -s -X GET "$BASE_URL/tokens/1/price-history?timeframe=24h" | jq '.'

echo -e "\n📝 12. 获取交易历史"
curl -s -X GET "$BASE_URL/tokens/1/trades?page=1&limit=5" | jq '.'

echo -e "\n✅ BSC LaunchPad API 测试完成!"
